<!doctype html>
<!--[if lt IE 7]>
<html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->

<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>Activiti Editor</title>
	<meta name="description" content="">
	<meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, width=device-width">
	<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->

	<link rel="Stylesheet" media="screen" href="editor-app/libs/ng-grid-2.0.7.min.css" type="text/css" />
	<link rel="stylesheet" href="editor-app/libs/bootstrap_3.1.1/css/bootstrap.min.css" />

	<link rel="Stylesheet" media="screen" href="editor-app/editor/css/editor.css" type="text/css" />
	<link rel="stylesheet" href="editor-app/css/style.css" type="text/css" />

	<link rel="stylesheet" href="editor-app/css/style-common.css">
	<link rel="stylesheet" href="editor-app/css/style-editor.css">

</head>

<body>
	<div id="main" class="wrapper full clearfix" ng-style="{height: window.height + 'px'}" ng-app="activitiModeler"
	 ng-include="'editor-app/editor.html'"></div>
	<hidden ng-init="onLoad()" />
	<!--[if lt IE 9]>
	<script src="editor-app/libs/es5-shim-15.3.4.5/es5-shim.js"></script>
	<script src="editor-app/libs/json3_3.2.6/lib/json3.min.js"></script>
	<![endif]-->

	<script src="editor-app/libs/jquery_1.11.0/jquery.min.js"></script>
	<script src="editor-app/libs/jquery-ui-1.10.3.custom.min.js"></script>

	<script src="editor-app/libs/angular_1.2.13/angular.min.js"></script>
	<script src="editor-app/libs/angular_1.2.13/angular-animate.min.js"></script>
	<script src="editor-app/libs/bootstrap_3.1.1/js/bootstrap.min.js"></script>
	<script src="editor-app/libs/angular-resource_1.2.13/angular-resource.min.js"></script>
	<script src="editor-app/libs/angular-cookies_1.2.13/angular-cookies.min.js"></script>
	<script src="editor-app/libs/angular-sanitize_1.2.13/angular-sanitize.min.js"></script>
	<script src="editor-app/libs/angular-route_1.2.13/angular-route.min.js"></script>
	<script src="editor-app/libs/angular-translate_2.4.2/angular-translate.min.js"></script>
	<script src="editor-app/libs/angular-translate-storage-cookie/angular-translate-storage-cookie.js"></script>
	<script src="editor-app/libs/angular-translate-loader-static-files/angular-translate-loader-static-files.js"></script>
	<script src="editor-app/libs/angular-strap_2.0.5/angular-strap.min.js"></script>
	<script src="editor-app/libs/angular-strap_2.0.5/angular-strap.tpl.min.js"></script>
	<script src="editor-app/libs/momentjs_2.5.1/momentjs.min.js"></script>

	<script src="editor-app/libs/ui-utils.min-0.0.4.js" type="text/javascript"></script>
	<script src="editor-app/libs/ng-grid-2.0.7-min.js" type="text/javascript"></script>
	<script src="editor-app/libs/angular-dragdrop.min-1.0.3.js" type="text/javascript"></script>
	<script src="editor-app/libs/mousetrap-1.4.5.min.js" type="text/javascript"></script>
	<script src="editor-app/libs/jquery.autogrow-textarea.js" type="text/javascript"></script>

	<script src="editor-app/libs/prototype-1.5.1.js" type="text/javascript"></script>
	<script src="editor-app/libs/path_parser.js" type="text/javascript"></script>

	<script src="editor-app/libs/angular-scroll_0.5.7/angular-scroll.min.js" type="text/javascript"></script>

	<!-- Configuration -->
	<script src="editor-app/app-cfg.js?v=1"></script>
	<script src="editor-app/editor-config.js" type="text/javascript"></script>
	<script src="editor-app/configuration/url-config.js" type="text/javascript"></script>

	<script src="editor-app/editor/i18n/translation_en_us.js" type="text/javascript"></script>
	<script src="editor-app/editor/i18n/translation_signavio_en_us.js" type="text/javascript"></script>
	<script src="editor-app/editor/oryx.debug.js" type="text/javascript"></script>

	<script src="editor-app/app.js"></script>

	<script src="editor-app/eventbus.js" type="text/javascript"></script>

	<script src="editor-app/editor-controller.js" type="text/javascript"></script>
	<script src="editor-app/stencil-controller.js" type="text/javascript"></script>
	<script src="editor-app/toolbar-controller.js" type="text/javascript"></script>
	<script src="editor-app/header-controller.js" type="text/javascript"></script>
	<script src="editor-app/select-shape-controller.js" type="text/javascript"></script>

	<script src="editor-app/editor-utils.js" type="text/javascript"></script>
	<script src="editor-app/configuration/toolbar-default-actions.js" type="text/javascript"></script>

	<script src="editor-app/configuration/properties-default-controllers.js" type="text/javascript"></script>
	<script src="editor-app/configuration/properties-execution-listeners-controller.js" type="text/javascript"></script>
	<script src="editor-app/configuration/properties-event-listeners-controller.js" type="text/javascript"></script>
	<script src="editor-app/configuration/properties-assignment-controller.js" type="text/javascript"></script>
	<script src="editor-app/configuration/properties-fields-controller.js" type="text/javascript"></script>
	<script src="editor-app/configuration/properties-form-properties-controller.js" type="text/javascript"></script>
	<script src="editor-app/configuration/properties-in-parameters-controller.js" type="text/javascript"></script>
	<script src="editor-app/configuration/properties-multiinstance-controller.js" type="text/javascript"></script>
	<script src="editor-app/configuration/properties-out-parameters-controller.js" type="text/javascript"></script>
	<script src="editor-app/configuration/properties-task-listeners-controller.js" type="text/javascript"></script>
	<script src="editor-app/configuration/properties-sequenceflow-order-controller.js" type="text/javascript"></script>
	<script src="editor-app/configuration/properties-condition-expression-controller.js" type="text/javascript"></script>
	<script src="editor-app/configuration/properties-signal-definitions-controller.js" type="text/javascript"></script>
	<script src="editor-app/configuration/properties-signal-scope-controller.js" type="text/javascript"></script>
	<script src="editor-app/configuration/properties-message-definitions-controller.js" type="text/javascript"></script>
	<script src="editor-app/configuration/properties-message-scope-controller.js" type="text/javascript"></script>

	<script src="editor-app/configuration/toolbar.js" type="text/javascript"></script>
	<script src="editor-app/configuration/toolbar-custom-actions.js" type="text/javascript"></script>

	<script src="editor-app/configuration/properties.js" type="text/javascript"></script>
	<script src="editor-app/configuration/properties-custom-controllers.js" type="text/javascript"></script>
	<script>
		var _flReady = false;
		var _parentObj = null;

		// 设置全屏编辑按钮触发的回调事件
		function ibzOryxFullScree() {
			if (_parentObj) {
				_parentObj.showFullScreen();
			}
		}

		// 设置所有节点的双击事件回调
		function ibizActOnDBLClick($event, data) {
			if (_parentObj) {
				_parentObj.editShape(data);
			}
		}

		// 设置模型
		function setModel(data) {
			if (!data) {
				return;
			}
			try {
				data = JSON.parse(data);
			} catch (error) {
				console.log('JSON格式转换错误');
				console.log(error);
			}
			var modelData = {};
			modelData.name = data.name;
			modelData.description = data.description;
			modelData.model = data.json_xml;
			window.ibizSetModel(modelData);
			console.log(data);
		}

		// 获取模型
		function getModel() {
			var $editor = window.$editor;
			var $scope = window.$scope;

			var modelMetaData = $scope.editor.getModelMetaData();

			var json = $scope.editor.getJSON();

			var selection = $scope.editor.getSelection();
			// $scope.editor.setSelection([]);

			var svgClone = $scope.editor.getCanvas().getSVGRepresentation(true);
			// $scope.editor.setSelection(selection);
			if ($scope.editor.getCanvas().properties["oryx-showstripableelements"] === false) {
				var stripOutArray = jQuery(svgClone).find(".stripable-element");
				for (var i = stripOutArray.length - 1; i >= 0; i--) {
					stripOutArray[i].remove();
				}
			}

			// Remove all forced stripable elements
			var stripOutArray = jQuery(svgClone).find(".stripable-element-force");
			for (var i = stripOutArray.length - 1; i >= 0; i--) {
				stripOutArray[i].remove();
			}

			// Parse dom to string
			var svgDOM = DataManager.serialize(svgClone);

			var description = '';
			if (modelMetaData.description) {
				description = modelMetaData.description;
			}

			var params = {
				json_xml: json,
				svg_xml: svgDOM,
				name: modelMetaData.name,
				description: description
			};
			return JSON.stringify(params);
		}

		function setParentObj(obj) {
			_parentObj = obj;
			if (_flReady) {
				_parentObj.loadConfig();
			}
		}

		function onLoad() {
			_flReady = true;
			if (_parentObj) {
				_parentObj.loadConfig();
			}
		}

		function updateProcess(obj) {
			console.log('updateProcess');
			if (obj) {
				var facade = getFacade(obj);
				if (facade) {
					if (facade.getCanvas())
						facade.getCanvas().update();
					facade.updateSelection();
				}
			}
		}

		function updateConnection(obj) {
			console.log('updateConnection');
			if (obj) {
				var facade = getFacade(obj);
				if (facade) {
					if (facade.getCanvas())
						facade.getCanvas().update();
					facade.updateSelection();
				}
			}
		}

		function getFacade(obj) {
			if (obj.facade)
				return obj.facade;
			if (obj.parent) {
				return getFacade(obj.parent);
			}
			return null;
		}

	</script>
</body>
<script>
	/* angular.element(document).ready(function () {
		setTimeout(function () {
			onLoad();
			var isEnd = false;
			var loadEnd = function () {
				if (window.editorOnLoad && typeof window.editorOnLoad === 'function') {
					window.editorOnLoad();
				} else {
					isEnd = true;
				}
				if (!isEnd) {
					setTimeout(() => {
						loadEnd();
					}, 100);
				}
			};
			loadEnd();
		}, 10);
	}); */

	var SelectionChangedTimeOut = null;
	ORYX.Plugins.AbstractPlugin.prototype.onSelectionChanged = function () {
		if (SelectionChangedTimeOut) {
			clearTimeout(SelectionChangedTimeOut);
		}
		SelectionChangedTimeOut = setTimeout(function () {
			if (window.onSelectionChanged && typeof window.onSelectionChanged === 'function') {
				window.onSelectionChanged();
			}
		}, 500) //返回计时器 ID 
	};
	
	
	var isEnd = false;
	function activitiLoaded(){
		if (window.editorOnLoad && typeof window.editorOnLoad === 'function') {
			window.editorOnLoad();
		} else {
			isEnd = true;
		}
		if (!isEnd) {
			setTimeout(() => {
				activitiLoaded();
			}, 100);
		}
	}
	ORYX.Plugins.AbstractPlugin.prototype.onLoaded = function () {
		console.log('activiti loaded');
		onLoad();
		activitiLoaded();
	};

</script>

</html>